package com.example.demo.services;

import com.example.demo.dao.LabelDao;
import com.example.demo.model.CategoryModel;
import com.example.demo.model.LabelModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LabelService {

    @Resource
    LabelDao labelDao;

    @Value("10")
    private int limit;

    /**
     * 获取最热门的十条标签数据
     * @return
     */
    public List<LabelModel> getRecommendLabelList(int limit){
        return labelDao.getRecommendLabelList(limit);
    }

    public List<LabelModel> getRecommendLabelList(){
        return labelDao.getRecommendLabelList(limit);
    }

    public PageInfo getLabelListFromDb(
            int pageNum,
            int pageSize
    ) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo(getLabelListFromDb(""));
    }

    /**
     * 获取标签所有列表
     * @return
     */
    public List<LabelModel> getLabelListFromDb(String title){
        return labelDao.getLabelList(title);
    }

    public LabelModel getLabelInfo(Long id) {
        return labelDao.getLabelInfoById(id);
    }

    public int add(LabelModel labelModel) {
        return labelDao.addLabel(labelModel);
    }

    public boolean edit(LabelModel labelModel) {
        return labelDao.updateLabelById(labelModel);
    }

    public boolean del(Long id){ return labelDao.del(id); }

}
